local skel = fk.CreateSkill{
  name = "#rmt_halberd_skill",
  attached_equip = "rmt_halberd",
}

Fk:loadTranslationTable{
  ["#rmt_halberd_skill"] = "裂穹画戟",
  ["#rmt_halberd-choose"] = "你可发动〖裂穹画戟〗，额外指定两名目标",

  ["#RmtHalberdTargets"] = "%from 发动了〖%arg〗，令 %to 也成为 %card 的目标",
  ["#RmtHalberdNullified"] = "由于〖%arg〗的效果，%from 的 %arg2 对所有目标无效",
}

skel:addEffect(fk.AfterCardTargetDeclared, {
  anim_type = "offensive",
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and data.card.trueName == "slash" and #data:getExtraTargets() > 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local tos = room:askToChoosePlayers(player, {
      min_num = 1, max_num = 2,
      skill_name = skel.name,
      prompt = "#rmt_halberd-choose",
      targets = data:getExtraTargets(),
    })
    if #tos > 0 then
      event:setCostData(self, { tos = tos })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:broadcastPlaySound("./packages/standard_cards/audio/card/halberd")
    room:setEmotion(player, "./packages/standard_cards/image/anim/halberd")
    local tos = event:getCostData(self).tos
    data.extra_data = data.extra_data or {}
    data.extra_data.rmt_halberd = true
    room:sendLog{
      type = "#RmtHalberdTargets",
      from = player.id,
      to = table.map(tos, Util.IdMapper),
      arg = "rmt_halberd",
      card = Card:getIdList(data.card),
    }
    for _, p in ipairs(tos) do
      data:addTarget(p)
    end
  end
})

skel:addEffect(fk.CardEffectCancelledOut, {
  is_delay_effect = true,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if target == player and data.card.trueName == "slash" then
      local parent = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
      return parent and parent.data and parent.data.extra_data and parent.data.extra_data.rmt_halberd
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local e = room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
    if e == nil then return end
    local use = e.data
    if #use.tos > 0 then
      room:sendLog{
        type = "#RmtHalberdNullified",
        from = target.id,
        arg = skel.name,
        arg2 = data.card:toLogString(),
      }
      use.nullifiedTargets = table.simpleClone(use.tos)
    end
  end,
})

return skel
